﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;

public partial class system_systemcatalogmagview : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin("system configuration");
        switch (RequestBase.GetFormString("otype"))
        {
            case "delete":
                Delete();
                break;
            case "getnodetype":
                GetNodeType();
                break;
        }
    }

    void GetNodeType()
    {
        string entityType = "EnumDef";
        string enumDefId = RequestBase.GetFormString("_itemid");
        if (enumDefId != "{00000000-0000-0000-0000-000000000000}")
        {
            object _obj = BLL.CommonBLL.ExecuteScalar("EnumDef", "COUNT(1)", " AND EnumDefId = '" + enumDefId + "'");
            if (_obj != null && (int)_obj > 0)
            {
                entityType = "EnumItem";
            }
            else
            {
                _obj = BLL.CommonBLL.ExecuteScalar("EnumItem", "COUNT(1)", " AND EnumItemId = '" + enumDefId + "'");
                if (_obj != null && (int)_obj > 0)
                {
                    entityType = "Not allowed";
                }
            }
        }

        BLL.AjaxHelper.ResponseWrite(entityType);
    }

    #region 删除
    void Delete()
    {
        string res = "";
        string enumDefId = RequestBase.GetFormString("catalogid");
        if (enumDefId != "{00000000-0000-0000-0000-000000000000}" && enumDefId != "00000000-0000-0000-0000-000000000000")
        {
            try
            {
                object _obj = BLL.Search.CommonSearch.ExecScalar("EnumDef",
                    "COUNT(1)",
                    new string[] { "EnumDefId" },
                    new string[] { "Equal" },
                    new string[] { "'" + enumDefId + "'" },
                    null,
                    null);
                if (_obj != null && (int)_obj > 0)
                {
                    BLL.Sys.EnumDef.Delete(enumDefId);
                }
                else
                {
                    BLL.Sys.EnumItem.Delete(enumDefId);
                }
                res = "succeeded";
            }
            catch (Exception err) { res = err.Message; } 
        }
        else
            res = "参数错误！";

        BLL.AjaxHelper.ResponseWrite(res);
    }
    #endregion
}
